@{block #content}

<script type="text/javascript">
    function callSaveGalleryForm() {
        if(!nette.validateForm(document.getElementById("frmsaveGalleryForm-submitted"))) return false;
	    $.ajax({
		url: $("#frm-saveGalleryForm").attr("action"),
		dataType: 'json',
		data: getArrayFromForm("frm-saveGalleryForm"),
		type: "post",
		success: function (payload) {
		    $("#celebriogalleryapp_saveGalleryForm_snippet").html(payload.snippets["snippet--saveGalleryForm"]);
		}
	    });
	    $("#celebriogalleryapp_saveGalleryForm_snippet").html("");
	    return false;
    }
    
    function callSavePhotoForm() {
            if(!nette.validateForm(document.getElementById("frmsavePhotoForm-submitted"))) return false;
           
	    $.ajax({
		url: $("#frm-savePhotoForm").attr("action"),
		dataType: 'json',
		data: getArrayFromForm("frm-savePhotoForm"),
		type: "post",
		success: function (payload) {
		    $("#celebriogalleryapp_savePhotoForm_snippet").html(payload.snippets["snippet--savePhotoForm"]);
		}
	    });
	    $("#celebriogalleryapp_savePhotoForm_snippet").html("");
	    return false;
    }
    function addNextPhotoInput() {
        $('#frmsavePhotoForm-addNext').before('<div class="savePhotoInput"><input type="text" name="neco" /></div>');
    }
    
</script>
{snippet saveGalleryForm}
<div id="celebriogalleryapp_saveGalleryForm_snippet">
    
{$saveGalleryForm}
{/snippet}

</div>
{snippet savePhotoForm}
<div id="celebriogalleryapp_savePhotoForm_snippet">
{if !empty($photoErr)}
{$photoErr}
{/if}
{$savePhotoForm}
</div>
<div id="celebrioGalleryApp_test">
	<div id="celebrioGalleryApp_test_text">This view is only a draft, sorry for any bugs :)</div>
</div>
<script type="text/javascript">
		$(document).ready(function(){
                    addHidden();
                    $('#frmsavePhotoForm-newGallery').click(function(event) {
                        removeHidden();
                    });
		    $("#frmsaveGalleryForm-submitted").click(function(event){
		       event.preventDefault();
		       callSaveGalleryForm();
		    });
                    
                    $("#frmsavePhotoForm-submitted").click(function(event){
                        //$("#frmsavePhotoForm-newGalleryName").val("");
                        //$("frmsavePhotoForm-newGallery").removeAttr('checked');
		       //event.preventDefault();
		       //callSavePhotoForm();
		    });
                    
                    $('#frmsavePhotoForm-addNext').click(function(event) {
                        event.preventDefault();
                        addNextPhotoInput();
                    });
		});
                function addHidden() {
                    $("#frmsavePhotoForm-newGalleryName").addClass("hidden").toggle(0);
                    $('//label[for="frmsavePhotoForm-newGalleryName"]').addClass('hidden').toggle(0);
                }

                function removeHidden() {
                    $("#frmsavePhotoForm-newGalleryName").removeClass("hidden").toggle(0);
                    $('//label[for="frmsavePhotoForm-newGalleryName"]').removeClass('hidden').toggle(0);
                }
	    </script>
{/snippet}
{/block}